<?php

namespace App\Model;

use PhalApi\Model\DataModel;


class IdcardFromUnitTotal extends DataModel
{

    public $tableName = 'idcard_from_unit_total';
    protected function getTableName($id)
    {
        return $this->tableName;
    }

    //存入数据
    public function total_from_unit($data)
    {
        //重构新数组
        $new_data = array();
        foreach ($data as $k => $v){
            if ($v){
                $new_data[$k]=$v;
            }
        }
        //
        if ( $data['from_unit'] ){
            //处理送检单位,总和
            $where = array(
                "from_unit" => $data['from_unit'],
                "unit" => $data['unit']
            );
            $new_data['update_time'] = date("Y-m-d H:i:s", time());
            //查询结果
            $info = $this->getORM()->select('id')->where($where)->fetchOne();
            //如果有信息,就返回相关数组
            if ($info) {
                return "";
            }
            $new_data['create_time'] = date("Y-m-d H:i:s", time());
            $this->getORM()->insert($new_data);
        }
    }

}
